package com.application.chiettinhdienluc.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.application.chiettinhdienluc.R;

public class HoSoChietTinhItemPopMenuAdapter extends BaseAdapter{

	ArrayList<HoSoItemPopupMenuItem> itemList;
	private boolean isEditMode = false;

	public ArrayList<HoSoItemPopupMenuItem> getItemList() {
		return itemList;
	}

	public void setItemList(ArrayList<HoSoItemPopupMenuItem> itemList) {
		this.itemList = new ArrayList<HoSoItemPopupMenuItem>(itemList);
	}

	public Context context;
	public LayoutInflater inflater;	

	public HoSoChietTinhItemPopMenuAdapter(Context context) {
		super();
		this.context = context;
		this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public void setEditMode(boolean isEditmode)
	{
		this.isEditMode = isEditmode;
	}

	@Override
	public int getCount() {
		if(itemList != null)
			return itemList.size();
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if(itemList != null)
			return itemList.get(position);
		return null;
	}

	public int getMenuItemId(int position)
	{
		if(itemList == null)
			return -1;

		return itemList.get(position).mId;
	}

	@Override
	public long getItemId(int position) {	
		return 0;
	}

	public static class ViewHolder
	{
		public TextView name;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;

		try {
			if(convertView==null)
			{
				holder = new ViewHolder();
				convertView = inflater.inflate(R.layout.hoso_chiettinh_popmenu_row, null);

				holder.name = (TextView) convertView.findViewById(R.id.text);

				convertView.setTag(holder);
			}
			else
				holder=(ViewHolder)convertView.getTag();

			if(itemList != null && position >= 0 && position < itemList.size())
			{
				String item = itemList.get(position).mLabel;
				holder.name.setVisibility(View.GONE);
				if(item.length() > 0)
				{
					holder.name.setVisibility(View.VISIBLE);
					holder.name.setText(item);
				}
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}

		return convertView;
	}

	public static class HoSoItemPopupMenuItem
	{
		public final int mId;
		public final String mLabel;

		public HoSoItemPopupMenuItem(int id, String label)
		{
			mId = id;
			mLabel = label;
		}
	}

}
